// ***********************************************************
//  CUtil.cpp - utility class containing static functions
//
//  REVISION  DATE      AUTHOR			MODIFICATION
//  Rev-1     Spring07  CPA				Original author, CSSE
//  Rev-2     9/13/08   VN (Vu Nguyen)  Modified method int FindStringsCaseInsensitive
//                                        to fix detect in case %> is used in HTML
//                                        e.g., "width=100%>"
//                                      Added methods FindCharAvoidEscape(), ListFiles()
//  Rev-3     5/12/09   VN	            Mod042909AS: Included memory leak fixes provided by Aaron Shumate of NGC
// ***********************************************************

#ifndef CUTIL_H
#define CUTIL_H

#include "cc_main.h"

typedef vector<string> vectorString;

#define INVALID_POSITION ((unsigned int)-1) //Mod042909AS
#define TO_END_OF_STRING INVALID_POSITION

class CUtil
{
public:
	static string TrimString(string str = NULL);
	static string to_lower (string string_to_lower);
	static bool CheckBlank(string str);
	static bool isInteger(string);
	static size_t FindCharAvoidEscape(string source, char target, size_t start_idx, char escape);
	static size_t FindStringsCaseInsensitive(string target, map<string,int>& table, size_t& pos, size_t preLang = INVALID_POSITION); //Mod042909AS
#ifndef UNIX
	static void ListFiles(string &folder, string &fileExt, vectorString &fileList);
#endif

	// ------------------   Duplication Modification -----------------------
	static void ListAllFiles(string &folder, vectorString &fileExtList, vectorString &fileList);
	static void CountTally(string, StringVector&, int&, int, string, string, string, IntPairVector* counter_container = 0, bool dup = false, bool casesensitive = true);

	static size_t FindKeyword(string &str, string keyword, size_t start = 0, size_t end = TO_END_OF_STRING, bool casesensitive = true); //Mod042909AS
	static string ExtractFilename(string const &filepath);

	int static PrintFileHeader(ofstream &pout, string const title);
	string static ConvertClearCaseFile(string fileName);
	static void AddError(string err);

	static size_t TruncateLine(size_t length, size_t totalLength, size_t truncate, bool &trunc_flag);
};

#endif
